<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="入库单号(订单号前缀'rk_批次号')" prop="rkdh">
        <el-input
          v-model="queryParams.rkdh"
          placeholder="请输入入库单号(订单号前缀'rk_批次号')"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单ID" prop="ddid">
        <el-input
          v-model="queryParams.ddid"
          placeholder="请输入订单ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单号" prop="ddh">
        <el-input
          v-model="queryParams.ddh"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料ID" prop="wlid">
        <el-input
          v-model="queryParams.wlid"
          placeholder="请输入物料ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料编码" prop="wlbm">
        <el-input
          v-model="queryParams.wlbm"
          placeholder="请输入物料编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="物料名称" prop="wlmc">
        <el-input
          v-model="queryParams.wlmc"
          placeholder="请输入物料名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单位" prop="dw">
        <el-input
          v-model="queryParams.dw"
          placeholder="请输入单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单数量" prop="sl">
        <el-input
          v-model="queryParams.sl"
          placeholder="请输入订单数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订货商机构ID" prop="dhsDeptId">
        <el-input
          v-model="queryParams.dhsDeptId"
          placeholder="请输入订货商机构ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订货商部门名称" prop="dhsDeptName">
        <el-input
          v-model="queryParams.dhsDeptName"
          placeholder="请输入订货商部门名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供应商部门名称" prop="deptName">
        <el-input
          v-model="queryParams.deptName"
          placeholder="请输入供应商部门名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供应商部门ID,后台按部门名称查询" prop="deptId">
        <el-input
          v-model="queryParams.deptId"
          placeholder="请输入供应商部门ID,后台按部门名称查询"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="库位" prop="kw">
        <el-input
          v-model="queryParams.kw"
          placeholder="请输入库位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="入库类型" prop="rklx">
        <el-input
          v-model="queryParams.rklx"
          placeholder="请输入入库类型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="入库数量" prop="rksl">
        <el-input
          v-model="queryParams.rksl"
          placeholder="请输入入库数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注" prop="bz">
        <el-input
          v-model="queryParams.bz"
          placeholder="请输入备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="入库人" prop="rkr">
        <el-input
          v-model="queryParams.rkr"
          placeholder="请输入入库人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="入库时间">
        <el-date-picker
          v-model="daterangeRksj"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="录入人" prop="createby">
        <el-input
          v-model="queryParams.createby"
          placeholder="请输入录入人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="录入时间" prop="createtime">
        <el-input
          v-model="queryParams.createtime"
          placeholder="请输入录入时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新人" prop="updateby">
        <el-input
          v-model="queryParams.updateby"
          placeholder="请输入更新人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新时间" prop="updatetime">
        <el-input
          v-model="queryParams.updatetime"
          placeholder="请输入更新时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否删除,0否1是" prop="sfsc">
        <el-input
          v-model="queryParams.sfsc"
          placeholder="请输入是否删除,0否1是"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:ddrkmx:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:ddrkmx:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:ddrkmx:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:ddrkmx:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="ddrkmxList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="订单入库明细ID" align="center" prop="ddrkmxid" />
      <el-table-column label="入库单号(订单号前缀'rk_批次号')" align="center" prop="rkdh" />
      <el-table-column label="订单ID" align="center" prop="ddid" />
      <el-table-column label="订单号" align="center" prop="ddh" />
      <el-table-column label="物料ID" align="center" prop="wlid" />
      <el-table-column label="物料编码" align="center" prop="wlbm" />
      <el-table-column label="物料名称" align="center" prop="wlmc" />
      <el-table-column label="单位" align="center" prop="dw" />
      <el-table-column label="订单数量" align="center" prop="sl" />
      <el-table-column label="订货商机构ID" align="center" prop="dhsDeptId" />
      <el-table-column label="订货商部门名称" align="center" prop="dhsDeptName" />
      <el-table-column label="供应商部门名称" align="center" prop="deptName" />
      <el-table-column label="供应商部门ID,后台按部门名称查询" align="center" prop="deptId" />
      <el-table-column label="库位" align="center" prop="kw" />
      <el-table-column label="入库类型" align="center" prop="rklx" />
      <el-table-column label="入库数量" align="center" prop="rksl" />
      <el-table-column label="备注" align="center" prop="bz" />
      <el-table-column label="入库人" align="center" prop="rkr" />
      <el-table-column label="入库时间" align="center" prop="rksj" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.rksj, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="录入人" align="center" prop="createby" />
      <el-table-column label="录入时间" align="center" prop="createtime" />
      <el-table-column label="更新人" align="center" prop="updateby" />
      <el-table-column label="更新时间" align="center" prop="updatetime" />
      <el-table-column label="是否删除,0否1是" align="center" prop="sfsc" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:ddrkmx:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:ddrkmx:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改进销存_订单入库明细对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="入库单号(订单号前缀'rk_批次号')" prop="rkdh">
          <el-input v-model="form.rkdh" placeholder="请输入入库单号(订单号前缀'rk_批次号')" />
        </el-form-item>
        <el-form-item label="订单ID" prop="ddid">
          <el-input v-model="form.ddid" placeholder="请输入订单ID" />
        </el-form-item>
        <el-form-item label="订单号" prop="ddh">
          <el-input v-model="form.ddh" placeholder="请输入订单号" />
        </el-form-item>
        <el-form-item label="物料ID" prop="wlid">
          <el-input v-model="form.wlid" placeholder="请输入物料ID" />
        </el-form-item>
        <el-form-item label="物料编码" prop="wlbm">
          <el-input v-model="form.wlbm" placeholder="请输入物料编码" />
        </el-form-item>
        <el-form-item label="物料名称" prop="wlmc">
          <el-input v-model="form.wlmc" placeholder="请输入物料名称" />
        </el-form-item>
        <el-form-item label="单位" prop="dw">
          <el-input v-model="form.dw" placeholder="请输入单位" />
        </el-form-item>
        <el-form-item label="订单数量" prop="sl">
          <el-input v-model="form.sl" placeholder="请输入订单数量" />
        </el-form-item>
        <el-form-item label="订货商机构ID" prop="dhsDeptId">
          <el-input v-model="form.dhsDeptId" placeholder="请输入订货商机构ID" />
        </el-form-item>
        <el-form-item label="订货商部门名称" prop="dhsDeptName">
          <el-input v-model="form.dhsDeptName" placeholder="请输入订货商部门名称" />
        </el-form-item>
        <el-form-item label="供应商部门名称" prop="deptName">
          <el-input v-model="form.deptName" placeholder="请输入供应商部门名称" />
        </el-form-item>
        <el-form-item label="供应商部门ID,后台按部门名称查询" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入供应商部门ID,后台按部门名称查询" />
        </el-form-item>
        <el-form-item label="库位" prop="kw">
          <el-input v-model="form.kw" placeholder="请输入库位" />
        </el-form-item>
        <el-form-item label="入库类型" prop="rklx">
          <el-input v-model="form.rklx" placeholder="请输入入库类型" />
        </el-form-item>
        <el-form-item label="入库数量" prop="rksl">
          <el-input v-model="form.rksl" placeholder="请输入入库数量" />
        </el-form-item>
        <el-form-item label="备注" prop="bz">
          <el-input v-model="form.bz" placeholder="请输入备注" />
        </el-form-item>
        <el-form-item label="入库人" prop="rkr">
          <el-input v-model="form.rkr" placeholder="请输入入库人" />
        </el-form-item>
        <el-form-item label="入库时间" prop="rksj">
          <el-date-picker clearable
            v-model="form.rksj"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择入库时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="是否删除,0否1是" prop="sfsc">
          <el-input v-model="form.sfsc" placeholder="请输入是否删除,0否1是" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDdrkmx, getDdrkmx, delDdrkmx, addDdrkmx, updateDdrkmx } from "@/api/system/ddrkmx";

export default {
  name: "Ddrkmx",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 进销存_订单入库明细表格数据
      ddrkmxList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否删除,0否1是时间范围
      daterangeRksj: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        rkdh: null,
        ddid: null,
        ddh: null,
        wlid: null,
        wlbm: null,
        wlmc: null,
        dw: null,
        sl: null,
        dhsDeptId: null,
        dhsDeptName: null,
        deptName: null,
        deptId: null,
        kw: null,
        rklx: null,
        rksl: null,
        bz: null,
        rkr: null,
        rksj: null,
        createby: null,
        createtime: null,
        updateby: null,
        updatetime: null,
        sfsc: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        ddid: [
          { required: true, message: "订单ID不能为空", trigger: "blur" }
        ],
        ddh: [
          { required: true, message: "订单号不能为空", trigger: "blur" }
        ],
        rkr: [
          { required: true, message: "入库人不能为空", trigger: "blur" }
        ],
        createby: [
          { required: true, message: "录入人不能为空", trigger: "blur" }
        ],
        createtime: [
          { required: true, message: "录入时间不能为空", trigger: "blur" }
        ],
        updateby: [
          { required: true, message: "更新人不能为空", trigger: "blur" }
        ],
        updatetime: [
          { required: true, message: "更新时间不能为空", trigger: "blur" }
        ],
        sfsc: [
          { required: true, message: "是否删除,0否1是不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询进销存_订单入库明细列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeRksj && '' != this.daterangeRksj) {
        this.queryParams.params["beginRksj"] = this.daterangeRksj[0];
        this.queryParams.params["endRksj"] = this.daterangeRksj[1];
      }
      listDdrkmx(this.queryParams).then(response => {
        this.ddrkmxList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        ddrkmxid: null,
        rkdh: null,
        ddid: null,
        ddh: null,
        wlid: null,
        wlbm: null,
        wlmc: null,
        dw: null,
        sl: null,
        dhsDeptId: null,
        dhsDeptName: null,
        deptName: null,
        deptId: null,
        kw: null,
        rklx: null,
        rksl: null,
        bz: null,
        rkr: null,
        rksj: null,
        createby: null,
        createtime: null,
        updateby: null,
        updatetime: null,
        sfsc: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeRksj = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.ddrkmxid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加进销存_订单入库明细";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const ddrkmxid = row.ddrkmxid || this.ids
      getDdrkmx(ddrkmxid).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改进销存_订单入库明细";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.ddrkmxid != null) {
            updateDdrkmx(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDdrkmx(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ddrkmxids = row.ddrkmxid || this.ids;
      this.$modal.confirm('是否确认删除进销存_订单入库明细编号为"' + ddrkmxids + '"的数据项？').then(function() {
        return delDdrkmx(ddrkmxids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/ddrkmx/export', {
        ...this.queryParams
      }, `ddrkmx_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
